package net.xiaoyu233.mitemod.miteite.render.entity;

import net.minecraft.*;
import net.xiaoyu233.mitemod.miteite.entity.EntityHellWither;
import net.xiaoyu233.mitemod.miteite.render.entity.model.EntityHellWitherModel;
import org.lwjgl.opengl.GL11;


public class RenderHellWither extends bhe {

    public static final int body_texture = 0;
    public static final int body_texture_invulnerable = 1;
    private int modelVersion;

    public RenderHellWither() {
        super(new EntityHellWitherModel(), 1.0F);
        this.modelVersion = ((EntityHellWitherModel)this.i).a();
    }

    public void a(EntityHellWither par1EntityWither, double par2, double par4, double par6, float par8, float par9) {
        bez.a(par1EntityWither, true);
        int var10 = ((EntityHellWitherModel)this.i).a();
        if (var10 != this.modelVersion) {
            this.modelVersion = var10;
            this.i = new EntityHellWitherModel();
        }

        super.a(par1EntityWither, par2, par4, par6, par8, par9);
    }

    protected bjo a(EntityHellWither par1EntityWither) {
        int var2 = par1EntityWither.func_82212_n();
        return var2 <= 0 || var2 <= 80 && var2 / 5 % 2 == 1 ? this.textures[0] : this.textures[1];
    }
    protected void a(EntityHellWither par1EntityWither, float partialTicks) {
        int invulnTime = par1EntityWither.func_82212_n();

        float scale = 2.0F; // 基础缩放

        // 应用阶段体型缩放
        if (par1EntityWither instanceof EntityHellWither) {
            EntityHellWither hellWither = par1EntityWither;
            scale *= hellWither.getCurrentScale();

            // 根据阶段改变颜色效果
            switch (hellWither.getPhase()) {
                case 1:
                    // 第一阶段：正常颜色
                    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
                    break;
                case 2:
                    // 第二阶段：轻微红色调
                    GL11.glColor4f(1.0F, 0.9F, 0.9F, 1.0F);
                    break;
                case 3:
                    // 第三阶段：明显的红色调
                    GL11.glColor4f(1.0F, 0.8F, 0.8F, 1.0F);
                    break;
            }
        }

        if (invulnTime > 0) {
            float invulnScale = 2.0F - ((float)invulnTime - partialTicks) / 220.0F * 0.5F;
            scale *= invulnScale;

            // 地狱凋零特有的效果：在无敌状态下有轻微的红光
            if (invulnTime > 0) {
                float redIntensity = 0.5F + (float)Math.sin(par1EntityWither.ticksExisted * 0.2F) * 0.1F;
                GL11.glColor4f(1.0F, redIntensity, redIntensity, 1.0F);
            }
        }

        GL11.glScalef(scale, scale, scale);

    }
    protected int a(EntityHellWither par1EntityWither, int par2, float par3) {
        if (par1EntityWither.isArmored()) {
            if (par1EntityWither.isInvisible()) {
                GL11.glDepthMask(false);
            } else {
                GL11.glDepthMask(true);
            }

            if (par2 == 1) {
                float var4 = (float)par1EntityWither.ticksExisted + par3;
                this.a((bjo)this.textures[1]);
                GL11.glMatrixMode(5890);
                GL11.glLoadIdentity();
                float var5 = MathHelper.cos(var4 * 0.02F) * 3.0F;
                float var6 = var4 * 0.01F;
                GL11.glTranslatef(var5, var6, 0.0F);
                this.a((bbo)this.i);
                GL11.glMatrixMode(5888);
                GL11.glEnable(3042);
                float intensity = 0.5F;
                // 地狱凋零护甲效果使用红色调
                GL11.glColor4f(1.0F, intensity * 0.7F, intensity * 0.5F, 1.0F);
                GL11.glDisable(GL11.GL_LIGHTING);
                GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
                GL11.glTranslatef(0.0F, -0.01F, 0.0F);
                GL11.glScalef(1.1F, 1.1F, 1.1F);
                return 1;
            }

            if (par2 == 2) {
                GL11.glMatrixMode(GL11.GL_TEXTURE);
                GL11.glLoadIdentity();
                GL11.glMatrixMode(GL11.GL_MODELVIEW);
                GL11.glEnable(GL11.GL_LIGHTING);
                GL11.glDisable(GL11.GL_BLEND);
            }
        }

        return -1;
    }
    protected int b(EntityHellWither par1EntityWither, int par2, float par3) {
        return -1;
    }
    public void a(EntityInsentient par1EntityLiving, double par2, double par4, double par6, float par8, float par9) {
        this.a((EntityHellWither)par1EntityLiving, par2, par4, par6, par8, par9);
    }

    protected void a(EntityLiving par1EntityLivingBase, float par2) {
        this.a((EntityHellWither)par1EntityLivingBase, par2);
    }

    protected int a(EntityLiving par1EntityLivingBase, int par2, float par3) {
        return this.a((EntityHellWither)par1EntityLivingBase, par2, par3);
    }

    protected int b(EntityLiving par1EntityLivingBase, int par2, float par3) {
        return this.b((EntityHellWither)par1EntityLivingBase, par2, par3);
    }

    public void a(EntityLiving par1EntityLivingBase, double par2, double par4, double par6, float par8, float par9) {
        this.a((EntityHellWither)par1EntityLivingBase, par2, par4, par6, par8, par9);
    }
    public void a(Entity par1Entity, double par2, double par4, double par6, float par8, float par9) {
        this.a((EntityHellWither)par1Entity, par2, par4, par6, par8, par9);
    }

    @Override
    protected bjo a(Entity entity) {
        return this.a((EntityHellWither) entity);
    }

    @Override
    protected void setTextures() {
        this.setTexture(0, "textures/entity/wither/witherBoss");
        this.setTexture(1, "textures/entity/wither/wither_invulnerable");
    }
}
